<template>
 <view class="fui-wrap">
	 
	 <fui-row margin-bottom="24rpx">
	 	<fui-col>
	 		 
		<view class="fui-align__center fui-color__black">
		 
			
			<fui-row v-if="token" margin-bottom="24rpx">
				<fui-col :span="12">
					<fui-avatar size="large" :src="user.avatar" radius="30"/>
				</fui-col>
				<fui-col :span="12">
					<view >{{user.nickName}}</view>
					<view   v-if="user.status==0">普通用户</view>
					<view   v-else>会员</view>
				</fui-col>
			</fui-row>
			
		  
		  <fui-button v-else :margin="['24rpx']"  @click="wxlogin()" type="link" color="#465CFF">微信登录</fui-button>
	   </view>
			 
	 	</fui-col>
	 </fui-row>
	 <view >
		 <view >
			 <fui-list-cell arrow @click="false">
			 	<view class="fui-list__item fui-align__center" >
			 		<text>开通会员</text>
			 	</view>
			 </fui-list-cell>
		 	<fui-list-cell arrow @click="toPage('/pages/views/myOrder')">
		 		<view class="fui-list__item fui-align__center" >
		 			<text>我的订单</text>
		 		</view>
		 	</fui-list-cell>
			<fui-list-cell arrow @click="toPage('/pages/views/myContestMakeList')">
				<view class="fui-list__item fui-align__center" >
					<text>我的预约</text>
				</view>
			</fui-list-cell>
			<fui-list-cell arrow @click="toPage('/pages/views/mySeek?type=1')">
				<view class="fui-list__item fui-align__center" >
					<text>关于我们</text>
				</view>
			</fui-list-cell>
			<fui-list-cell arrow >
				<view class="fui-list__item fui-align__center">
					<text>分享</text>
				</view>
			</fui-list-cell>
		 </view>
	</view>
		<fui-button v-if="token" radius="0"  @click="outLogin()">退出登录</fui-button>
</view>
</template>

<script>
	export default {
		data() {
			return {
				token:"",
				user:{}
			}
		},
		onLoad() {
			this.token=uni.getStorageSync("token")
			this.user=uni.getStorageSync("user")
		},
		methods: {
			toPage(paths){
				uni.navigateTo({
					url: paths
				});
			},
			outLogin(){
				uni.clearStorageSync()
				uni.switchTab({
					url: '/pages/views/home'
				});

			},
			wxlogin(){
              var that = this
				 uni.login({
				     provider: 'weixin',
				     success: function (loginRes) {
						   uni.getUserInfo({
						       provider: 'weixin',
						       success: function(info) {
								   var userInfo =info.userInfo;
						          var obj={
						          		 loginCode:loginRes.code,
						          		 phoneCode:'',
						          		nickName:userInfo.nickName,
						          		 imageUrl:userInfo.avatarUrl
						          }
								  that.$request.post('wx/login', obj).then(res => {
								          let data = res.data;
										  that.token = data.authorization
										  that.user = data.currnetUser
										  
										 uni.setStorageSync("user",that.user)
										 uni.setStorageSync("token",that.token)
										 if(!that.user.phonenumber){
										 
											 uni.navigateTo({
											 	url: '/pages/tabbar/modifyPhone?userId='+that.user.userId
											 });

										 }
										  
								  })
						       }
						   })
				     },
				     fail: function (err) {
				         // 登录授权失败
				         // err.code是错误码
				     }
				 });

			}
		}
	}
</script>

<style>

	.fui-col__item {
		height: 84rpx;
		border-radius: 16rpx;
	}	
	.fui-color__black {
		background-color: white;
	}
</style>
